home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / full / jbuild / setup / JBuilder / jsamples.z / test.jar / sunw / demo / test / BridgeTester.class (.txt) next >
Encoding:
Java Class File  |  1997-06-04  |  13.0 KB  |  578 lines

  1. package sunw.demo.test;
  2.  
  3. import java.awt.Button;
  4. import java.awt.Checkbox;
  5. import java.awt.Container;
  6. import java.awt.Dimension;
  7. import java.awt.GridLayout;
  8. import java.awt.Label;
  9. import java.awt.Panel;
  10. import java.awt.TextField;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.KeyEvent;
  14. import java.awt.event.KeyListener;
  15. import java.awt.event.MouseEvent;
  16. import java.awt.event.MouseListener;
  17. import java.beans.PropertyChangeListener;
  18. import java.beans.PropertyChangeSupport;
  19. import java.beans.PropertyVetoException;
  20. import java.beans.VetoableChangeListener;
  21. import java.beans.VetoableChangeSupport;
  22. import java.util.EventObject;
  23. import java.util.Vector;
  24.  
  25. public class BridgeTester extends Panel implements ActionListener, KeyListener, MouseListener {
  26.    private int intValue;
  27.    private short shortValue;
  28.    private double doubleValue;
  29.    private float floatValue;
  30.    private char charValue;
  31.    private byte byteValue;
  32.    private boolean booleanValue;
  33.    private String stringValue;
  34.    private long longValue;
  35.    private int[] intArray;
  36.    private double[] doubleArray;
  37.    private String[] stringArray;
  38.    private float[] floatArray;
  39.    private char[] charArray;
  40.    private short[] shortArray;
  41.    private byte[] byteArray;
  42.    private boolean[] booleanArray;
  43.    private TextField intField;
  44.    private TextField doubleField;
  45.    private TextField shortField;
  46.    private TextField floatField;
  47.    private TextField charField;
  48.    private TextField byteField;
  49.    private Checkbox booleanField;
  50.    private TextField stringField;
  51.    private Button event1Button;
  52.    private Button event2Button;
  53.    private Button event3Button;
  54.    private Button event4Button;
  55.    private TextField array1;
  56.    private TextField array2;
  57.    private TextField array3;
  58.    private TextField array4;
  59.    private PropertyChangeSupport changes = new PropertyChangeSupport(this);
  60.    private VetoableChangeSupport vetos = new VetoableChangeSupport(this);
  61.    private Vector listeners = new Vector();
  62.    private Vector actionListeners = new Vector();
  63.  
  64.    public BridgeTester() {
  65.       ((Container)this).setLayout(new GridLayout(6, 4, 10, 10));
  66.       this.event1Button = new Button("Fire Event 1 ");
  67.       this.event1Button.addActionListener(this);
  68.       ((Container)this).add(this.event1Button);
  69.       this.event2Button = new Button("Fire Event 2 ");
  70.       this.event2Button.addActionListener(this);
  71.       ((Container)this).add(this.event2Button);
  72.       this.event3Button = new Button("Fire Event 3 ");
  73.       this.event3Button.addActionListener(this);
  74.       ((Container)this).add(this.event3Button);
  75.       this.event4Button = new Button("Fire Event 4 ");
  76.       this.event4Button.addActionListener(this);
  77.       ((Container)this).add(this.event4Button);
  78.       ((Container)this).add(new Label("Int Value : "));
  79.       this.intField = new TextField();
  80.       this.intField.addKeyListener(this);
  81.       ((Container)this).add(this.intField);
  82.       this.doubleField = new TextField();
  83.       ((Container)this).add(new Label("Double Value : "));
  84.       this.doubleField.addKeyListener(this);
  85.       ((Container)this).add(this.doubleField);
  86.       ((Container)this).add(new Label("Short Value :"));
  87.       this.shortField = new TextField();
  88.       this.shortField.addKeyListener(this);
  89.       ((Container)this).add(this.shortField);
  90.       ((Container)this).add(new Label("Float Value :"));
  91.       this.floatField = new TextField();
  92.       this.floatField.addKeyListener(this);
  93.       ((Container)this).add(this.floatField);
  94.       ((Container)this).add(new Label("Char Value :"));
  95.       this.charField = new TextField();
  96.       this.charField.addKeyListener(this);
  97.       ((Container)this).add(this.charField);
  98.       ((Container)this).add(new Label("Byte Value :"));
  99.       this.byteField = new TextField();
  100.       this.byteField.addKeyListener(this);
  101.       ((Container)this).add(this.byteField);
  102.       ((Container)this).add(new Label("String value :"));
  103.       this.stringField = new TextField();
  104.       this.stringField.addKeyListener(this);
  105.       ((Container)this).add(this.stringField);
  106.       ((Container)this).add(new Label("Boolean Value :"));
  107.       this.booleanField = new Checkbox();
  108.       this.booleanField.addMouseListener(this);
  109.       ((Container)this).add(this.booleanField);
  110.       this.array1 = new TextField();
  111.       ((Container)this).add(this.array1);
  112.       this.array2 = new TextField();
  113.       ((Container)this).add(this.array2);
  114.       this.array3 = new TextField();
  115.       ((Container)this).add(this.array3);
  116.       this.array4 = new TextField();
  117.       ((Container)this).add(this.array4);
  118.       int[] var1 = new int[]{1, 2, 3, 4, 5};
  119.       this.setIntArray(var1);
  120.       double[] var2 = new double[]{1.1, 2.2, 3.3, 4.4, (double)5.5F};
  121.       this.setDoubleArray(var2);
  122.       String[] var3 = new String[]{"TOTO", "s'en", "va", "en", "guerre"};
  123.       this.setStringArray(var3);
  124.       float[] var4 = new float[]{1.01F, 2.02F, 3.03F, 4.04F, 5.05F};
  125.       this.setFloatArray(var4);
  126.       char[] var5 = new char[]{'A', 'B', 'c', 'd', 'E'};
  127.       this.setCharArray(var5);
  128.       byte[] var6 = new byte[]{1, 2, 3, 4, 5};
  129.       this.setByteArray(var6);
  130.       short[] var7 = new short[]{5, 4, 3, 2, 1};
  131.       this.setShortArray(var7);
  132.       boolean[] var8 = new boolean[]{true, false, false, true, false};
  133.       this.setBooleanArray(var8);
  134.    }
  135.  
  136.    public Dimension getPreferredSize() {
  137.       return new Dimension(400, 200);
  138.    }
  139.  
  140.    /** @deprecated */
  141.    public Dimension preferredSize() {
  142.       return this.getPreferredSize();
  143.    }
  144.  
  145.    public void setIntValue(int var1) throws PropertyVetoException {
  146.       int var2 = this.intValue;
  147.       this.vetos.fireVetoableChange("intValue", new Integer(var2), new Integer(var1));
  148.       this.intValue = var1;
  149.       this.intField.setText(String.valueOf(this.intValue));
  150.       this.changes.firePropertyChange("intValue", new Integer(var2), new Integer(var1));
  151.    }
  152.  
  153.    public int getIntValue() {
  154.       return this.intValue;
  155.    }
  156.  
  157.    public void setDoubleValue(double var1) {
  158.       double var3 = this.doubleValue;
  159.       this.doubleValue = var1;
  160.       this.doubleField.setText(String.valueOf(this.doubleValue));
  161.       this.changes.firePropertyChange("doubleValue", new Double(var3), new Double(var1));
  162.    }
  163.  
  164.    public double getDoubleValue() {
  165.       return this.doubleValue;
  166.    }
  167.  
  168.    public void setShortValue(short var1) {
  169.       short var2 = this.shortValue;
  170.       this.shortValue = var1;
  171.       this.shortField.setText(String.valueOf(this.shortValue));
  172.       this.changes.firePropertyChange("shortValue", new Short(var2), new Short(var1));
  173.    }
  174.  
  175.    public short getShortValue() {
  176.       return this.shortValue;
  177.    }
  178.  
  179.    public void setFloatValue(float var1) {
  180.       float var2 = this.floatValue;
  181.       this.floatValue = var1;
  182.       this.floatField.setText(String.valueOf(this.floatValue));
  183.       this.changes.firePropertyChange("floatValue", new Float(var2), new Float(var1));
  184.    }
  185.  
  186.    public float getFloatValue() {
  187.       return this.floatValue;
  188.    }
  189.  
  190.    public void setCharValue(char var1) {
  191.       char var2 = this.charValue;
  192.       this.charValue = var1;
  193.       this.charField.setText(String.valueOf(this.charValue));
  194.       this.changes.firePropertyChange("charValue", new Character(var2), new Character(var1));
  195.    }
  196.  
  197.    public char getCharValue() {
  198.       return this.charValue;
  199.    }
  200.  
  201.    public void setByteValue(byte var1) {
  202.       byte var2 = this.byteValue;
  203.       this.byteValue = var1;
  204.       this.byteField.setText(String.valueOf(this.byteValue));
  205.       this.changes.firePropertyChange("byteValue", new Byte(var2), new Byte(var1));
  206.    }
  207.  
  208.    public void setByteValue(int var1) {
  209.       this.setByteValue((byte)var1);
  210.    }
  211.  
  212.    public byte getByteValue() {
  213.       return this.byteValue;
  214.    }
  215.  
  216.    public void setLongValue(long var1) {
  217.       this.longValue = var1;
  218.    }
  219.  
  220.    public long getLongValue() {
  221.       return this.longValue;
  222.    }
  223.  
  224.    public boolean isBooleanValue() {
  225.       return this.booleanValue;
  226.    }
  227.  
  228.    public void setBooleanValue(boolean var1) {
  229.       boolean var2 = this.booleanValue;
  230.       this.booleanValue = var1;
  231.       this.booleanField.setState(this.booleanValue);
  232.       this.changes.firePropertyChange("booleanValue", new Boolean(var2), new Boolean(var1));
  233.    }
  234.  
  235.    public String getStringValue() {
  236.       return this.stringValue;
  237.    }
  238.  
  239.    public void setStringValue(String var1) {
  240.       String var2 = this.stringValue;
  241.       this.stringValue = var1;
  242.       this.stringField.setText(this.stringValue);
  243.       this.changes.firePropertyChange("stringValue", var2, var1);
  244.    }
  245.  
  246.    public int[] getIntArray() {
  247.       return this.intArray;
  248.    }
  249.  
  250.    public void setIntArray(int[] var1) {
  251.       this.intArray = var1;
  252.       this.array1.setText(String.valueOf(this.intArray[0]));
  253.       this.array2.setText(String.valueOf(this.intArray[1]));
  254.       this.array3.setText(String.valueOf(this.intArray[2]));
  255.       this.array4.setText(String.valueOf(this.intArray[3]));
  256.    }
  257.  
  258.    public void setIntArrayWithIndex(int var1, int var2) {
  259.       this.intArray[var1] = var2;
  260.    }
  261.  
  262.    public int getIntArrayWithIndex(int var1) {
  263.       return this.intArray[var1];
  264.    }
  265.  
  266.    public double[] getDoubleArray() {
  267.       return this.doubleArray;
  268.    }
  269.  
  270.    public void setDoubleArray(double[] var1) {
  271.       this.doubleArray = var1;
  272.       this.array1.setText(String.valueOf(this.doubleArray[0]));
  273.       this.array2.setText(String.valueOf(this.doubleArray[1]));
  274.       this.array3.setText(String.valueOf(this.doubleArray[2]));
  275.       this.array4.setText(String.valueOf(this.doubleArray[3]));
  276.    }
  277.  
  278.    public void setDoubleArrayWithIndex(int var1, double var2) {
  279.       this.doubleArray[var1] = var2;
  280.    }
  281.  
  282.    public double getDoubleArrayWithIndex(int var1) {
  283.       return this.doubleArray[var1];
  284.    }
  285.  
  286.    public String[] getStringArray() {
  287.       return this.stringArray;
  288.    }
  289.  
  290.    public void setStringArray(String[] var1) {
  291.       this.stringArray = var1;
  292.       this.array1.setText(this.stringArray[0]);
  293.       this.array2.setText(this.stringArray[1]);
  294.       this.array3.setText(this.stringArray[2]);
  295.       this.array4.setText(this.stringArray[3]);
  296.    }
  297.  
  298.    public void setStringArrayWithIndex(int var1, String var2) {
  299.       this.stringArray[var1] = var2;
  300.    }
  301.  
  302.    public String getStringArrayWithIndex(int var1) {
  303.       return this.stringArray[var1];
  304.    }
  305.  
  306.    public byte[] getByteArray() {
  307.       return this.byteArray;
  308.    }
  309.  
  310.    public void setByteArray(byte[] var1) {
  311.       this.byteArray = var1;
  312.       this.array1.setText(String.valueOf(this.byteArray[0]));
  313.       this.array2.setText(String.valueOf(this.byteArray[1]));
  314.       this.array3.setText(String.valueOf(this.byteArray[2]));
  315.       this.array4.setText(String.valueOf(this.byteArray[3]));
  316.    }
  317.  
  318.    public void setByteArrayWithIndex(int var1, byte var2) {
  319.       this.byteArray[var1] = var2;
  320.    }
  321.  
  322.    public byte getByteArrayWithIndex(int var1) {
  323.       return this.byteArray[var1];
  324.    }
  325.  
  326.    public float[] getFloatArray() {
  327.       return this.floatArray;
  328.    }
  329.  
  330.    public void setFloatArray(float[] var1) {
  331.       this.floatArray = var1;
  332.       this.array1.setText(String.valueOf(this.floatArray[0]));
  333.       this.array2.setText(String.valueOf(this.floatArray[1]));
  334.       this.array3.setText(String.valueOf(this.floatArray[2]));
  335.       this.array4.setText(String.valueOf(this.floatArray[3]));
  336.    }
  337.  
  338.    public void setFloatArrayWithIndex(int var1, float var2) {
  339.       this.floatArray[var1] = var2;
  340.    }
  341.  
  342.    public float getFloatArrayWithIndex(int var1) {
  343.       return this.floatArray[var1];
  344.    }
  345.  
  346.    public char[] getCharArray() {
  347.       return this.charArray;
  348.    }
  349.  
  350.    public void setCharArray(char[] var1) {
  351.       this.charArray = var1;
  352.       this.array1.setText(String.valueOf(this.charArray[0]));
  353.       this.array2.setText(String.valueOf(this.charArray[1]));
  354.       this.array3.setText(String.valueOf(this.charArray[2]));
  355.       this.array4.setText(String.valueOf(this.charArray[3]));
  356.    }
  357.  
  358.    public void setCharArrayWithIndex(int var1, char var2) {
  359.       this.charArray[var1] = var2;
  360.    }
  361.  
  362.    public char getCharArrayWithIndex(int var1) {
  363.       return this.charArray[var1];
  364.    }
  365.  
  366.    public boolean[] getBooleanArray() {
  367.       return this.booleanArray;
  368.    }
  369.  
  370.    public void setBooleanArray(boolean[] var1) {
  371.       this.booleanArray = var1;
  372.       this.array1.setText(String.valueOf(this.booleanArray[0]));
  373.       this.array2.setText(String.valueOf(this.booleanArray[1]));
  374.       this.array3.setText(String.valueOf(this.booleanArray[2]));
  375.       this.array4.setText(String.valueOf(this.booleanArray[3]));
  376.    }
  377.  
  378.    public void setBooleanArrayWithIndex(int var1, boolean var2) {
  379.       this.booleanArray[var1] = var2;
  380.    }
  381.  
  382.    public boolean getBooleanArrayWithIndex(int var1) {
  383.       return this.booleanArray[var1];
  384.    }
  385.  
  386.    public short[] getShortArray() {
  387.       return this.shortArray;
  388.    }
  389.  
  390.    public void setShortArray(short[] var1) {
  391.       this.shortArray = var1;
  392.       this.array1.setText(String.valueOf(this.shortArray[0]));
  393.       this.array2.setText(String.valueOf(this.shortArray[1]));
  394.       this.array3.setText(String.valueOf(this.shortArray[2]));
  395.       this.array4.setText(String.valueOf(this.shortArray[3]));
  396.    }
  397.  
  398.    public void setShortArrayWithIndex(int var1, short var2) {
  399.       this.shortArray[var1] = var2;
  400.    }
  401.  
  402.    public short getShortArrayWithIndex(int var1) {
  403.       return this.shortArray[var1];
  404.    }
  405.  
  406.    public void printObjectInField(Object var1) {
  407.       if (var1 == null) {
  408.          this.stringField.setText("NULL REF");
  409.       } else {
  410.          this.stringField.setText(var1.toString());
  411.       }
  412.    }
  413.  
  414.    public void addPropertyChangeListener(PropertyChangeListener var1) {
  415.       this.changes.addPropertyChangeListener(var1);
  416.    }
  417.  
  418.    public void removePropertyChangeListener(PropertyChangeListener var1) {
  419.       this.changes.removePropertyChangeListener(var1);
  420.    }
  421.  
  422.    public void addVetoableChangeListener(VetoableChangeListener var1) {
  423.       this.vetos.addVetoableChangeListener(var1);
  424.    }
  425.  
  426.    public void removeVetoableChangeListener(VetoableChangeListener var1) {
  427.       this.vetos.removeVetoableChangeListener(var1);
  428.    }
  429.  
  430.    public synchronized void addBridgeTesterListener(BridgeTesterListener var1) {
  431.       this.listeners.addElement(var1);
  432.    }
  433.  
  434.    public synchronized void removeBridgeTesterListener(BridgeTesterListener var1) {
  435.       this.listeners.removeElement(var1);
  436.    }
  437.  
  438.    public ActionListener getActionListener() {
  439.       return new 1();
  440.    }
  441.  
  442.    private void fireEvent(int var1) {
  443.       synchronized(this){}
  444.  
  445.       Vector var2;
  446.       try {
  447.          var2 = (Vector)this.listeners.clone();
  448.       } catch (Throwable var7) {
  449.          throw var7;
  450.       }
  451.  
  452.       for(int var3 = 0; var3 < var2.size(); ++var3) {
  453.          BridgeTesterListener var4 = (BridgeTesterListener)var2.elementAt(var3);
  454.          switch (var1) {
  455.             case 1:
  456.                BridgeTesterEvent var5 = new BridgeTesterEvent(this, this.stringValue, this.intValue);
  457.                var4.eventNumber1(var5);
  458.                break;
  459.             case 2:
  460.                var4.eventNumber2(this.stringValue);
  461.                break;
  462.             case 3:
  463.                var4.eventNumber3(this.shortValue);
  464.                break;
  465.             case 4:
  466.                var4.eventNumber4(this.intArray);
  467.          }
  468.       }
  469.  
  470.    }
  471.  
  472.    public void actionPerformed(ActionEvent var1) {
  473.       Object var2 = ((EventObject)var1).getSource();
  474.       if (var2 == this.event1Button) {
  475.          this.fireEvent(1);
  476.       } else if (var2 == this.event2Button) {
  477.          this.fireEvent(2);
  478.       } else if (var2 == this.event3Button) {
  479.          this.fireEvent(3);
  480.       } else if (var2 == this.event4Button) {
  481.          this.fireEvent(4);
  482.       }
  483.    }
  484.  
  485.    public void keyPressed(KeyEvent var1) {
  486.    }
  487.  
  488.    public void keyTyped(KeyEvent var1) {
  489.    }
  490.  
  491.    public void keyReleased(KeyEvent var1) {
  492.       Object var2 = ((EventObject)var1).getSource();
  493.       if (var2 == this.stringField) {
  494.          this.setStringValue(this.stringField.getText());
  495.       } else if (var2 == this.doubleField) {
  496.          try {
  497.             double var16 = this.doubleValue;
  498.             this.doubleValue = new Double(this.doubleField.getText());
  499.             this.changes.firePropertyChange("doubleValue", new Double(var16), new Double(this.doubleValue));
  500.          } catch (NumberFormatException var5) {
  501.             this.doubleField.setText(String.valueOf(this.getDoubleValue()));
  502.          }
  503.       } else if (var2 == this.intField) {
  504.          int var15 = this.intValue;
  505.  
  506.          try {
  507.             int var4 = new Integer(this.intField.getText());
  508.             this.vetos.fireVetoableChange("intValue", new Integer(var15), new Integer(var4));
  509.             this.intValue = var4;
  510.             this.changes.firePropertyChange("intValue", new Integer(var15), new Integer(var4));
  511.          } catch (NumberFormatException var6) {
  512.             this.intField.setText(String.valueOf(this.getIntValue()));
  513.          } catch (PropertyVetoException var7) {
  514.             this.intField.setText(String.valueOf(this.getIntValue()));
  515.          }
  516.       } else if (var2 == this.shortField) {
  517.          try {
  518.             short var14 = this.shortValue;
  519.             this.shortValue = new Short(this.shortField.getText());
  520.             this.changes.firePropertyChange("shortValue", new Short(var14), new Short(this.shortValue));
  521.          } catch (NumberFormatException var8) {
  522.             this.shortField.setText(String.valueOf(this.getShortValue()));
  523.          }
  524.       } else if (var2 == this.floatField) {
  525.          try {
  526.             float var13 = this.floatValue;
  527.             this.floatValue = new Float(this.floatField.getText());
  528.             this.changes.firePropertyChange("floatValue", new Float(var13), new Float(this.floatValue));
  529.          } catch (NumberFormatException var9) {
  530.             this.floatField.setText(String.valueOf(this.getFloatValue()));
  531.          }
  532.       } else if (var2 == this.byteField) {
  533.          try {
  534.             byte var12 = this.byteValue;
  535.             this.byteValue = new Byte(this.byteField.getText());
  536.             this.changes.firePropertyChange("byteValue", new Byte(var12), new Byte(this.byteValue));
  537.          } catch (NumberFormatException var10) {
  538.             this.byteField.setText(String.valueOf(this.getByteValue()));
  539.          }
  540.       } else if (var2 == this.charField) {
  541.          try {
  542.             this.setCharValue(this.charField.getText().charAt(0));
  543.          } catch (NumberFormatException var11) {
  544.             char[] var3 = new char[]{this.getCharValue()};
  545.             this.charField.setText(new String(var3));
  546.          }
  547.       }
  548.    }
  549.  
  550.    public void mousePressed(MouseEvent var1) {
  551.    }
  552.  
  553.    public void mouseClicked(MouseEvent var1) {
  554.    }
  555.  
  556.    public void mouseEntered(MouseEvent var1) {
  557.    }
  558.  
  559.    public void mouseExited(MouseEvent var1) {
  560.    }
  561.  
  562.    public void mouseReleased(MouseEvent var1) {
  563.       if (((EventObject)var1).getSource() == this.booleanField) {
  564.          boolean var2 = this.booleanValue;
  565.          boolean var3;
  566.          if (this.booleanValue) {
  567.             var3 = false;
  568.          } else {
  569.             var3 = true;
  570.          }
  571.  
  572.          this.booleanValue = var3;
  573.          this.changes.firePropertyChange("booleanValue", new Boolean(var2), new Boolean(var3));
  574.       }
  575.  
  576.    }
  577. }
  578.